package com.rul.mars.product.controller;

import com.rul.mars.common.api.CommonPage;
import com.rul.mars.common.api.CommonResult;
import com.rul.mars.mbg.domain.CollectionDetail;
import com.rul.mars.product.service.ProductCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品服务接口
 *
 * @author RuL
 */
@Api(tags = "ProductCollectionController", description = "商品收藏服务接口")
@RestController
@RequestMapping(path = "/collection")
public class ProductCollectionController {

    @Autowired
    private ProductCollectionService productCollectionService;

    /**
     * 添加商品收藏
     *
     * @param productId 商品ID
     * @return 添加结果
     */
    @ApiOperation("添加商品收藏")
    @PostMapping("/add/{productId}")
    public CommonResult addCollection(@PathVariable(value = "productId") Long productId) {
        int count = productCollectionService.collectProduct(productId);
        if (count >= 1) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("查询我的所有商品收藏")
    @PostMapping("/list")
    public CommonResult<CommonPage<CollectionDetail>> listCollection() {
        List<CollectionDetail> collectionDetailList = productCollectionService.listCollection();

        return CommonResult.failed();
    }
}
